package controller;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;

import multiformat.Calculator;

public class CalculateController extends JPanel implements ActionListener {

	private static final long serialVersionUID = 1L;
	
	private JButton btnAdd;
	private JButton btnSubstract;
	private JButton btnMultiply;
	private JButton btnDivide;
	
	private Calculator model;
	
	public CalculateController(Calculator model) {
		this.model = model;
		this.setLayout(new GridLayout(2,2));
		
		this.btnAdd = new JButton("+");
		this.btnAdd.setBackground(Color.ORANGE);
		this.add(btnAdd);
		this.btnAdd.addActionListener(this);
		
		this.btnSubstract = new JButton("-");
		this.btnSubstract.setBackground(Color.ORANGE);
		this.add(btnSubstract);
		this.btnSubstract.addActionListener(this);
		
		this.btnMultiply = new JButton("*");
		this.btnMultiply.setBackground(Color.ORANGE);
		this.add(btnMultiply);
		this.btnMultiply.addActionListener(this);
		
		this.btnDivide = new JButton("/");
		this.btnDivide.setBackground(Color.ORANGE);
		this.add(btnDivide);
		this.btnDivide.addActionListener(this);
		
		this.validate();
		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == btnAdd) {
			model.add();
		}else if(e.getSource() == btnSubstract){
			model.subtract();
		}else if(e.getSource() == btnMultiply) {
			model.multiply();
		}else if(e.getSource() == btnDivide) {
			model.divide();
		}
	}

}
